import axios from "axios";

async function fetcha1() {
  try {
    const response = await axios.get("https://wxm.biteanbox.com/data/a1");
    return response.data.a1;
  } catch (error) {
    throw error;
  }
}

async function fetcha2() {
  try {
    const response = await axios.get("https://wxm.biteanbox.com/data/a2");
    return response.data.a2;
  } catch (error) {
    throw error;
  }
}

async function fetchb(a1, a2) {
  try {
    const response = await axios.get(
      `https://wxm.biteanbox.com/data/b?a1=${a1}&a2=${a2}`
    );
    return response.data;
  } catch (error) {
    throw error;
  }
}

async function getDataForb() {
  try {
    // 使用了Promise.all()方法，同时获取a1和a2的数据，
    // 如果有一个请求失败，则Promise.all()方法会抛出一个错误，导致整个函数执行失败。
    const [a1, a2] = await Promise.all([fetcha1(), fetcha2()]);
    const bData = await fetchb(a1, a2);
    return bData;
  } catch (error) {
    throw error;
  }
}

// 调用函数
getDataForb();
